<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"/>
    <title>showdown</title>
    <script type="text/javascript">
      var ws;
      function init() {
        ws = new WebSocket("ws://" + location.hostname + ":" + location.port + "/websocket");

        ws.onopen = function() {
          // output("onopend");
        }

        ws.onmessage = function(e) {
          // console.log(e.data);
          document.getElementById('output').innerHTML = e.data;
        }

        ws.onclose = function() {
          // output("onclose");
        }

        ws.onerror = function() {
          // output("onerror");
        }
      }

      function output(str) {
        var log     = document.getElementById('log');
        var escaped = str.replace(/&/, "&amp;").replace(/</, "&lt;").replace(/>/, "&gt;").replace(/"/, "&quot;");
        log.innerHTML = escaped + '<br>' + log.innerHTML;
      }
    </script>
  </head>
  <body onload="init();">
    <div id="log"></div>
    <div id="output"></div>
  </body>
</html>
